package com.shd.edanpei.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.shd.edanpei.R;
import com.shd.edanpei.enums.OrderTypeEnum;
import com.shd.edanpei.photo.PhotoViewActivity;
import com.shd.edanpei.ui.adapter.UpFileAdapter;
import com.shd.edanpei.base.BaseActivity;
import com.shd.edanpei.base.BasePresenterImpl;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.bean.ImgInfoBean;
import com.shd.edanpei.bean.UpFileBean;
import com.shd.edanpei.enums.PicEnum;
import com.shd.edanpei.image.LoadImageCtrl;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mc on 2018/4/4.
 * 订单图片资料查看页面
 */

public class PicShowActivity extends BaseActivity {


    public static final String INTENT_BACK_DATA = "result_back";
    public static final String INTENT_RESULT_CODE = "result_code";
    public static final String INTENT_PICA_DATA = "pica_data";
    public static final String INTENT_PICB_DATA = "picb_data";
    public static final int INTENT_REQUEST_CODE = 99;

    public static final int PIC = 1;
    public static final int PIC2 = 2;

    @BindView(R.id.headline)
    TextView headline;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    //上传证件类型
    private int mType;
    private ImgInfoBean imgInfoBean;
    private List<ImageView> viewList;
    private List<String> picList;

    private UpFileAdapter mAdapter;
    private List<UpFileBean> list = new ArrayList<>();
    private List<String> imgList = new ArrayList<>();
    private List<String> hintList = new ArrayList<>();
    private  int orderType;


    @Override
    protected int setLayout() {
        return R.layout.picshow_activity;
    }

    @Override
    protected BasePresenterImpl bindPresenter() {
        return null;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        loadImageCtrl = new LoadImageCtrl(this);
        headline.setText("上传文件");
        Bundle extras = getIntent().getExtras();
        mType = extras.getInt(Constant.TYPE);
        imgInfoBean = extras.getParcelable(Constant.DATA);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new UpFileAdapter(this, Constant.SHOW);
        recyclerView.setAdapter(mAdapter);
        orderType = extras.getInt(Constant.ORDER_TYPE);
        initData();
    }

    private void initData() {
        if (mType == PicEnum.idCardPic.getId()) {
            imgList = imgInfoBean.getIdCardPic();
            hintList.add("身份证正面");
            hintList.add("身份证反面");

        } else if (mType == PicEnum.householdRegister.getId()) {
            imgList = imgInfoBean.getHouseholdRegister();
            hintList.add("户口本主页");
            hintList.add("户口本个人页");
        } else if (mType == PicEnum.roomCert.getId()) {
            imgList = imgInfoBean.getRoomCert();
            hintList.add("房产证/不动产证");
        } else if (mType == PicEnum.businessCert.getId()) {
            imgList = imgInfoBean.getBusinessCert();
            hintList.add("营业执照");
        } else if (mType == PicEnum.otherHouseCert.getId()) {
            imgList = imgInfoBean.getOtherHouseCert();
            hintList.add("房产证/不动产证");
        } else if (mType == PicEnum.carCert.getId()) {
            imgList = imgInfoBean.getCarCert();
            hintList.add("车辆登记证");
            hintList.add("行驶证");
        } else if (mType == PicEnum.carWarranty.getId()) {
            imgList = imgInfoBean.getCarWarranty();
           //个人信用贷是保单信息
            if(orderType== OrderTypeEnum.personal.getKey()){
                hintList.add("保单信息");
            }else{
                hintList.add("车辆保单");
            }

        } else if (mType == PicEnum.maritalCert.getId()) {
            imgList = imgInfoBean.getMaritalCert();
            hintList.add("结婚证/离婚证");
        } else if (mType == PicEnum.creditCert.getId()) {
            imgList = imgInfoBean.getCreditCert();
            hintList.add("征信");
        } else if (mType == PicEnum.supplement.getId()) {
            imgList = imgInfoBean.getSupplement();
            hintList.add("信息补充");
        }else if (mType == PicEnum.newCreditCert.getId()) {
            imgList = imgInfoBean.getCreditCert();
            hintList.add("征信报告");
        }else if (mType == PicEnum.newBusinessCert.getId()) {
            imgList = imgInfoBean.getBusinessCert();
            hintList.add("公司营业执照");
        }else if (mType == PicEnum.newWarranty.getId()) {
            imgList = imgInfoBean.getCarWarranty();
            hintList.add("保单");
        }
        setImgData();
    }

    private void setImgData() {
        for (int i = 0; i < imgList.size(); i++) {
            list.add(new UpFileBean(imgList.get(i)));
        }

        for (int i = 0; i < hintList.size(); i++) {
            list.get(i).setDownStr(hintList.get(i));
        }

        mAdapter.setNewData(list);
    }


    private Bundle bundle = new Bundle();

    @Override
    protected void initListener() {
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                bundle.clear();
                ArrayList<String> list = new ArrayList<>();
                list.add(imgList.get(position));
                bundle.putStringArrayList(PhotoViewActivity.PHOTO_LIST, list);
                startActivity(PhotoViewActivity.class, bundle);
            }
        });
    }

    @OnClick(R.id.iv_headline_back)
    public void onViewClicked() {
        finish();
    }


}
